/**
 * Created by wangzilong on 2017/4/11.
 */
import React, { Component,PropTypes } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Image,
    ScrollView,
    TouchableOpacity,
    TextInput,
    ListView,
    Modal,
    Platform,
    InteractionManager
} from 'react-native';
import ImageWrapper from '../components/ImageWrapper';
import NavigationBar from '../components/NavigationBar';
import shopService from '../lib/services/shopService';
import StorageUser from '../lib/plugins/StorageUser';
var Dimensions = require('Dimensions');
const { width, height } = Dimensions.get('window');

export default class SubmitInfo extends Component{
    constructor(props) {
        super(props);
        this.token = '';
        this.userId = '';
        this.state = {
            status:0,
            stepText1:'未添加',
            stepStyle1:styles.waitColor,
            stepText2:'未审核',
            stepStyle2:styles.waitColor,
            stepText3:'未通过',
            stepStyle3:styles.waitColor,
            shopId:0,
        };
    }

    componentDidMount(){
        var $this = this;
        StorageUser._getUser()
            .then(data=>{
                if(data.userId){
                    $this.userId = data.userId;
                }
                if(data.token){
                    $this.token = data.token;
                }
                if(data.status){
                    if(data.status==1){
                        $this.setState({
                            status:data.status,
                            stepText1:'已提交',
                            stepStyle1:styles.passColor,
                            stepText2:'待审核',
                        })
                    }else if(data.status==3){
                        $this.setState({
                            status:data.status,
                            stepText1:'已提交',
                            stepStyle1:styles.passColor,
                            stepText12:'已审核',
                            stepStyle2:styles.passColor,
                            stepText13:'未通过',
                            stepStyle3:styles.unpassColor,
                        })
                    }
                }
                if(data.submitShopId&&data.submitShopId!=0){
                    $this.setState({
                            shopId:data.submitShopId
                        })
                }
            }).catch(err=> {
                console.log(err)
            }); 
    }
    render(){
        return (
            <View style={styles.container}>
                <NavigationBar titleText={'提交店铺资料'} />
                <View style={styles.navBox}>
                    <View style={[styles.statursBox,this.state.stepStyle1]}>
                        <Text style={{color:'#fff',fontSize:10}}>{this.state.stepText1}</Text>
                    </View>
                    <View style={styles.line}></View>
                    <View style={[styles.statursBox,this.state.stepStyle2]}>
                        <Text style={{color:'#fff',fontSize:10}}>{this.state.stepText2}</Text>
                    </View>
                    <View style={styles.line}></View>
                    <View style={[styles.statursBox,this.state.stepStyle3]}>
                        <Text style={{color:'#fff',fontSize:10}}>{this.state.stepText3}</Text>
                    </View>
                </View>
                <View style={{justifyContent:'center',alignItems:'center',height:60,marginTop:30}}>
                    <TouchableOpacity onPress={()=>this.goAddStore()} style={{width:80,height:30}}>
                        <View style={{justifyContent:'center',alignItems:'center',backgroundColor:'#169BD5',borderRadius:5,flex:1}}>
                            <Text style={{color:'#fff'}}>{this.state.status==3?'修改店铺':'添加店铺'}</Text>
                        </View>
                    </TouchableOpacity>
                </View>
                <View style={{justifyContent:'center',alignItems:'center',height:50}}>
                    <Text style={{color:'#000',fontSize:18}}>系统消息</Text>
                </View>
                <View style={{justifyContent:'center',alignItems:'center'}}>
                    <Text style={{color:'#000',fontSize:10}}>请您提交资料，陪它后台会尽快为您审核</Text>
                </View>
            </View>
        )

    }

    goAddStore(){
        var $this = this;
        if(this.state.status==0){
            const {navigate } = this.props.navigation;
            navigate('AddStore',{userId:$this.userId});
        }else if(this.state.status==3){
            const {navigate } = this.props.navigation;
            navigate('EditStore',{id:$this.state.shopId});
        } 
    }
}

const styles = StyleSheet.create({
    container:{
        flex:1,
        backgroundColor:'#fff',
        ...Platform.select({
            ios: {
                marginTop: 20
            },
            android: {
                marginTop:0
            },

        }),
    },
    navBox:{
        flexDirection:'row',
        padding:10,
        marginTop:10
    },
    statursBox:{
        borderWidth:1,
        borderColor:'#333',
        borderRadius:5,
        alignItems:'center',
        justifyContent:'center',
        height:20,
        width:50
    },
    line:{
        borderBottomWidth:1,
        borderBottomColor:'#333',
        margin:10,
        flex:1
    },
    waitColor:{
        backgroundColor:'#999'
    },
    passColor:{
        backgroundColor:'#66CD00'
    },
    unpassColor:{
        backgroundColor:'#FF0000'
    }
    
});